//@author A0096466N
//
// **********
//
// history class contains all the information required
// to undo or redo
//
// **********

#include "History.h"

History::History(void) {

}

History::~History(void) {

}

Event History::getPast() {
	if(_past.empty()) {
		throw exception("no history available to undo");
	}
	return _past.back();
}

Event History::getFuture() {
	if(_future.empty()) {
		throw exception("no future available to redo");
	}
	return _future.back();
}

vector<Task> History::getPastStore() {
	return _pastStore;
}

int History::getFutureSize() {
	return _future.size();
}

int History::getPastSize() {
	return _past.size();
}
void History::addStorage(vector<Task>store) {
	_pastStore = store;
	return;
}

void History::addToRecords(Event history) {
	_past.push_back(history);
	clearFuture();
	return;
}

// future should be cleared every time addToRecords() is called
void History::clearFuture() {
	_future.clear();
}

void History::eraseLast() {
	_past.pop_back();
}

// this is when undo is called. take the earliest history
// and put it in the future in case user wants to redo
void History::transferToFuture() {
	_future.push_back(_past.back());
	_past.pop_back();
}

// this is when 'redo' is called. take the future Task,
// put it in the history, and remove the future Task
void History::transferToPast() {
	assert(!_future.empty());
	_past.push_back(_future.back());
	
	_future.pop_back();
}

